package com.soft.mapper;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Dept;

@SpringBootTest
public class DeptMapperTest {
	@Autowired
	private DeptMapper deptMapper;
	//@Test
	public void SelectTest() {
		List<Dept> deptList = deptMapper.selectList(null);
		for(int i=0;i<deptList.size();i++) {
			System.out.println(deptList.get(i).getDeptno());
			System.out.println(deptList.get(i).getDeptName());
			System.out.println(deptList.get(i).getDeptLoc());
	}
}
	@Test
	public void selectIdTest() {
		Dept dept = deptMapper.selectById(3);
		System.out.println(dept.getDeptName());
	}
	@Test
	public void selectOneTest() {
		QueryWrapper<Dept> qw = new QueryWrapper<>();
		qw.gt("deptno",1);
		try {
			Dept dept = deptMapper.selectOne(qw);
			System.out.println(dept.getDeptName());
		}catch(Exception e) {
			System.out.println("重复");
		}
	}
	//@Test
	public void insertTest() {
		Dept dept = new Dept();
		dept.setDeptName("李部");
		dept.setDeptLoc("北川");
		deptMapper.insert(dept);
	}
	//@Test
	public void updateTest() {
		Dept dept=new Dept();
		dept.setDeptno("1");
		dept.setDeptName("aaa");
		dept.setDeptLoc("aaa");
		deptMapper.updateById(dept);
	}
	@Test
	public void updateQueryTest() {
		UpdateWrapper<Dept> uw = new UpdateWrapper<>();
		uw.gt("deptno", 4);
		Dept dept = new Dept();
		dept.setDeptLoc("新疆");
		int num = deptMapper.update(dept,uw);
		System.out.println(num);
	}
	//@Test
	public void deleteTest() {
		Dept dept = new Dept();
		dept.setDeptno("2");
		deptMapper.deleteById(dept);
	}
	//@Test
	public void deleteQueryTest() {
		QueryWrapper<Dept> qw = new QueryWrapper<>();
		qw.eq("dept_name", "李部");
		deptMapper.delete(qw);
	}
}
